﻿using Aptea.OpenXmlOffice;
using DocumentFormat.OpenXml.Spreadsheet;

namespace eCRAM.Bll
{
    public static class CramExcelStyle
    {
        public static readonly System.Drawing.Color BorderColor = System.Drawing.Color.FromArgb(153, 51, 102);

        private const string fontName = "Comic Sans MS";
        private const int fontSize = 10;
        public const BorderStyleValues ThickBorderValue = BorderStyleValues.Medium;


        public static ExcelCellStyle MonthStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    BackgroundColor = System.Drawing.Color.White,
                    Bold = true,
                    FontName = fontName,
                    FontSize = fontSize,
                    Borders = EnumBordure.All,
                    BorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                };
            }
        }

        public static ExcelCellStyle ThinStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    BackgroundColor = System.Drawing.Color.White,
                    FontName = fontName,
                    FontSize = fontSize,
                    HorizontalAlignment = HorizontalAlignmentValues.Center,
                    Borders = EnumBordure.All,
                    BorderStyle = new BorderStyle { Style = BorderStyleValues.Thin, Color = System.Drawing.Color.Black },
                 };
            }
        }

        /// <summary>
        /// Style des cellules visa situées en bout de ligne
        /// </summary>
        public static ExcelCellStyle VisaStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    BackgroundColor = System.Drawing.Color.White,
                    Bold = true,
                    FontName = fontName,
                    FontSize = fontSize,
                    Borders = EnumBordure.Right | EnumBordure.Left | EnumBordure.Bottom,
                    RightBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                    LeftBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                    BottomBorderStyle = new BorderStyle { Style = BorderStyleValues.Thin, Color = System.Drawing.Color.Black }
                };
            }
        }


        /// <summary>
        /// Style de la derniere cellule visa située en bout de ligne
        /// </summary>
        public static ExcelCellStyle LastVisaStyle
        {
            get
            {
                var style = VisaStyle;
                style.BottomBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor };
                return style;
            }
        }

        /// <summary>
        /// Style des cellules total situées en bout de ligne
        /// </summary>
        public static ExcelCellStyle TableTotalStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    BackgroundColor = System.Drawing.Color.White,
                    FontName = fontName,
                    FontSize = fontSize,
                    HorizontalAlignment = HorizontalAlignmentValues.Center,
                    Borders = EnumBordure.Right | EnumBordure.Bottom,
                    RightBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                    BottomBorderStyle = new BorderStyle { Style = BorderStyleValues.Thin, Color = System.Drawing.Color.Black },
                };
            }
        }

        /// <summary>
        /// Style de la derniere cellule total située en bout de ligne
        /// </summary>
        public static ExcelCellStyle LastTableTotalStyle
        {
            get
            {
                var style = TableTotalStyle;
                style.Borders |= EnumBordure.Bottom;
                style.BottomBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor };
                return style;
            }
        }


        public static ExcelCellStyle HolidayStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    BackgroundColor = System.Drawing.Color.LightGray,
                    Borders = EnumBordure.All,
                    BorderStyle = new BorderStyle { Style = BorderStyleValues.Thin, Color = System.Drawing.Color.Black },
                    HorizontalAlignment = HorizontalAlignmentValues.Center,
                };
            }
        }

        public static ExcelCellStyle TitleStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    BackgroundColor = System.Drawing.Color.White,
                    Bold = true,
                    FontName = fontName,
                    FontSize = 14,
                    HorizontalAlignment = HorizontalAlignmentValues.Center,
                    VerticalAlignment = VerticalAlignmentValues.Center
                };
            }
        }

        public static ExcelCellStyle DefaultBorderStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    BackgroundColor = System.Drawing.Color.White,
                    Bold = true,
                    FontName = fontName,
                    FontSize = fontSize,
                    HorizontalAlignment = HorizontalAlignmentValues.Left,
                    Borders = EnumBordure.All,
                    BorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor }
                };
            }
        }

        public static ExcelCellStyle CenteredDefaultBorderStyle
        {
            get
            {
                var style = DefaultBorderStyle;
                style.HorizontalAlignment = HorizontalAlignmentValues.Center;
                return style;
            }
        }


        public static ExcelCellStyle DefaultBottomCellBorderStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    Bold = true,
                    FontName = fontName,
                    FontSize = fontSize,
                    BackgroundColor = System.Drawing.Color.White,
                    Borders = EnumBordure.Right | EnumBordure.Left | EnumBordure.Bottom,
                    RightBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                    LeftBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                    BottomBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor }
                };
            }
        }

        public static ExcelCellStyle DefaultTopBorderStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    Bold = true,
                    FontName = fontName,
                    FontSize = fontSize,
                    BackgroundColor = System.Drawing.Color.White,
                    Borders = EnumBordure.Right | EnumBordure.Left | EnumBordure.Top,
                    RightBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                    LeftBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                    TopBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor }
                };
            }
        }

        public static ExcelCellStyle ReferenceBorderStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    FontName = fontName,
                    FontSize = fontSize,
                    BackgroundColor = System.Drawing.Color.White,
                    Borders = EnumBordure.Right | EnumBordure.Left | EnumBordure.Bottom,
                    RightBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                    BottomBorderStyle = new BorderStyle { Style = BorderStyleValues.Thin, Color = System.Drawing.Color.Black },
                    LeftBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor }
                };
            }
        }

        /// <summary>
        /// Style utilisé pour les cellules representant un jour actif dans le header du tableau
        /// </summary>
        public static ExcelCellStyle DayBorderStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    Bold = true,
                    FontName = fontName,
                    FontSize = fontSize,
                    BackgroundColor = System.Drawing.Color.White,
                    Borders = EnumBordure.Right | EnumBordure.Bottom | EnumBordure.Top,
                    RightBorderStyle = new BorderStyle {Style = BorderStyleValues.Thin, Color =  System.Drawing.Color.Black},
                    BottomBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                    TopBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                    HorizontalAlignment = HorizontalAlignmentValues.Center,
                };
            }
        }

        /// <summary>
        /// Style utilisé pour les cellules representant un jour inactif dans le corps du tableau
        /// </summary>
        public static ExcelCellStyle DisabledDay
        {
            get
            {
                var style = DayStyle;
                style.BackgroundColor = System.Drawing.Color.DarkGray;
                return style;
            }
        }





        /// <summary>
        /// Style utilisé pour les informations du bas de page
        /// </summary>
        public static ExcelCellStyle FooterStyle
        {
            get
            {
                return new ExcelCellStyle
                {
                    BackgroundColor = System.Drawing.Color.White,
                    Borders = EnumBordure.All,
                    BorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor },
                    
                };
            }
        }

        /// <summary>
        /// Style utilisé pour les cellules du tableau
        /// </summary>
        public static ExcelCellStyle DayStyle
        {
            get { return ThinStyle; }
        }

        /// <summary>
        /// Style de la cellule par défaut avec toutes les bordures fines
        /// </summary>
        public static ExcelCellStyle DefaultCellThinBorders
        {
            get
            {
                return new ExcelCellStyle
                {
                    Bold = true,
                    FontName = fontName,
                    FontSize = fontSize,
                    BackgroundColor = System.Drawing.Color.White,
                    Borders = EnumBordure.All,
                    RightBorderStyle = new BorderStyle { Style = BorderStyleValues.Thin, Color = BorderColor },
                    BottomBorderStyle = new BorderStyle { Style = BorderStyleValues.Thin, Color = BorderColor },
                    LeftBorderStyle = new BorderStyle { Style = BorderStyleValues.Thin, Color = BorderColor },
                    TopBorderStyle = new BorderStyle { Style = BorderStyleValues.Thin, Color = BorderColor },
                    HorizontalAlignment = HorizontalAlignmentValues.Center,
                };
            }
        }

        /// <summary>
        /// Recupére le style par défaut en mettant en épais les bordures specifiées
        /// </summary>
        /// <param name="thickBorders"></param>
        /// <returns></returns>
        public static ExcelCellStyle GetDefaultCellSyleWithThickBorders(EnumBordure thickBorders)
        {
            var style = DefaultCellThinBorders;
            if((thickBorders & EnumBordure.Bottom) == EnumBordure.Bottom)
            {
                style.BottomBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor };
            }

            if ((thickBorders & EnumBordure.Right) == EnumBordure.Right)
            {
                style.RightBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor };
            }


            if ((thickBorders & EnumBordure.Left) == EnumBordure.Left)
            {
                style.LeftBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor };
            }

            if ((thickBorders & EnumBordure.Top) == EnumBordure.Top)
            {
                style.TopBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor };
            }
            return style;
        }


        /// <summary>
        /// Style utilisé pour les cellules de la derniere ligne du tableau
        /// </summary>
        public static ExcelCellStyle LastDayStyle
        {
            get
            {
                var style = DayStyle;
                style.Borders |= EnumBordure.Bottom;
                style.BottomBorderStyle = new BorderStyle { Style = ThickBorderValue, Color = BorderColor }; 
                return style;
            }
        }
    }
}
